package com.vnie.mina.test;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

import com.vnie.mina.message.BaseMessage;

public class ByteRequestServerDecoder implements ProtocolDecoder {

	public BaseMessage message;
	
	public ByteRequestServerDecoder(BaseMessage receiverMessage){
		super();
		this.message = receiverMessage;
	}
	
	public void decode(IoSession arg0, IoBuffer arg1, ProtocolDecoderOutput arg2)
			throws Exception {
		if (arg1.remaining()>0) {
			byte[] retBytes = new byte[arg1.remaining()];
			System.arraycopy(arg1.array(), 0, retBytes, 0, arg1.remaining());
			arg1.flip();
			message.setEntity(retBytes);
			arg2.write(message);
		}
	}

	public void dispose(IoSession arg0) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void finishDecode(IoSession arg0, ProtocolDecoderOutput arg1)
			throws Exception {
		// TODO Auto-generated method stub
		
	}
	
	

}
